package com.h.extensions.config;

import com.h.extensions.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 延迟队列
 */
@Configuration
public class DelayConfig {
    // 延迟队列
    @Bean("delayQueue")
    public Queue delayQueue() {
        return QueueBuilder.durable(Constants.DELAY_QUEUE).build();
    }
    @Bean("delayExchange")
    // delayed() 这个就是延迟队列的标识 —— 需要实现安装 延迟队列插件
    public DirectExchange delayExchange() {
        return ExchangeBuilder.directExchange(Constants.DELAY_EXCHANGE).delayed().build();
    }
    @Bean("delayBinding")
    public Binding delayBinding(@Qualifier("delayExchange") Exchange exchange,
                                 @Qualifier("delayQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("delay").noargs();
    }

}
